//
//  InviteLogic.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/3/23.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "InviteLogic.h"
#import "InvitationModel.h"
@implementation InviteLogic
- (instancetype)init
{
    self = [super init];
    if (self) {
        _page = 1;
        _dataArray = [NSMutableArray array];
    }
    return self;
}


-(void)loadData
{
    if (_page == 1) {
        [_dataArray removeAllObjects];
    }

    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"invite_api" A:@"get_my_invite_page"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@(_page) forKey:@"page"];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        if (_page == 1) {
            [_dataArray removeAllObjects];
        }
        
        self.invite_code = [responseObject valueForKey:@"invite_code"];
        
        self.invite_user_count = NSStringFormat(@"%@",[responseObject valueForKey:@"invite_user_count"]);
        self.income_total =NSStringFormat(@"%@",[responseObject valueForKey:@"income_total"]);
        self.day_income_total =NSStringFormat(@"%@",[responseObject valueForKey:@"day_income_total"]) ;

        
        
        NSArray *list = [NSArray modelArrayWithClass:[InvitationModel class] json:[responseObject valueForKey:@"invite_user_list"]];
        [_dataArray addObjectsFromArray:list];
        
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } failure:^(NSString *error) {
        [[HUDHelper sharedInstance] tipMessage:error];
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } hasCache:YES];
}

@end
